include(default)
####################################################################################
# 基于NDK19C的profile模板                                                          #
####################################################################################
{# 获取当前平台名并转为小写,linux,windows,darwin....                              #}
{% set osname = platform.system() | lower                                         %}
{% set archname = {"AMD64": "x86_64"}.get(platform.machine(), platform.machine()) %}
{# 编译器执行程序后缀                                                             #}
{% set exe_suffix = {"Windows": ".cmd"}.get(platform.system(),"")                 %}
####################################################################################
# 从环境变量ANDROID_ABI中读取目标CPU架构，设置target_host,api_level                #
# 优先使用上级传入的 android_abi 变量,未定义则使用环境变量ANDROID_ABI              #
# 否则使用默认值armeabi-v7a                                                        #
####################################################################################
{% if not android_abi                                                             %}
{%     set android_abi = os.getenv("ANDROID_ABI","armeabi-v7a")                   %}
{% endif                                                                          %}
{% set target_host,target_arch,default_api_level = {
                "armeabi-v7a":("armv7a-linux-androideabi","armv7",16),
                "arm64-v8a"  :("aarch64-linux-android","armv8",21),
                "x86"        :("i686-linux-android","x86",16),
                "x86_64"     :("x86_64-linux-android","x86_64",21)}
                .get(android_abi,("unknow_host","unknow_arch",-1))                %}
{# 优先使用上级传入的 api_level 变量,未定义则使用环境变量ANDROID_NATIVE_API_LEVEL
   否则使用默认值 default_api_level                                               #}
{% if not api_level                                                               %}
{%     set api_level = os.getenv("ANDROID_NATIVE_API_LEVEL",default_api_level)    %}
{% endif                                                                          %}
# 从环境变量ANDROID_NDK中读取Android NDK安装位置
android_ndk={{ os.getenv("ANDROID_NDK") }}
[settings]
arch={{ target_arch }}
build_type=Release
compiler=clang
compiler.libcxx=c++_static
compiler.version=8
os=Android
os.api_level={{ api_level }}
[options]
{% if platform.system() == "Windows" %}
boost:addr2line_location=$android_ndk\toolchains\llvm\prebuilt\windows-x86_64\bin\x86_64-linux-android-addr2line.exe
{% endif %}
boost:without_stacktrace=True
[env]
{% set bin_path = "$android_ndk/toolchains/llvm/prebuilt/"~osname~"-"~archname~"/bin" %}
{% if platform.system() == "Windows" %}
# windows下替换路径分割符
PATH=[{{ bin_path | replace("/","\\") }}]
{% else %}
PATH=[{{ bin_path }}]
{% endif %}
CHOST={{ target_host }}
CC={{ target_host }}{{ api_level }}-clang{{ exe_suffix }}
CXX={{ target_host }}{{ api_level }}-clang++{{ exe_suffix }}
#########################################################################################
# 对于 32 位 ARM，编译器会使用前缀 armv7a-linux-androideabi,                            #
# 但 binutils 工具会使用前缀 arm-linux-androideabi。对于其他架构，所有工具的前缀都相同  #
# see also https://developer.android.com/ndk/guides/other_build_systems                 #
#########################################################################################
{% set binutils_prefix = { "armv7a-linux-androideabi":"arm-linux-androideabi"}
                          .get(target_host,target_host) %}
AR={{ binutils_prefix }}-ar
AS={{ binutils_prefix }}-as
RANLIB={{ binutils_prefix }}-ranlib
LD={{ binutils_prefix }}-ld
STRIP={{ binutils_prefix }}-strip
# 定义环境变量ANDROID_ABI,ANDROID_NATIVE_API_LEVEL,用于 conan_ndk_toolchain.cmake
ANDROID_ABI={{ android_abi }}
ANDROID_NATIVE_API_LEVEL={{ api_level }}
#########################################################################################
# 指定./conan/cmake/conan_ndk_toolchain.cmake 为cmake 工具链文件                        #
# ANDROID NDK默认提供的android.toolchain.cmake,                                         #
# 如果不指定ANDROID_ABI和 ANDROID_NATIVE_API_LEVEL或ANDROID_PLATFORM,                   #
# 默认编译的目标平台 armv7,所以不可以直接使用。                                         #
#########################################################################################
{% set toolchain = os.path.join(profile_dir, "..","cmake","conan_ndk_toolchain.cmake") %}
{% if platform.system() == "Windows" %}
CONAN_CMAKE_TOOLCHAIN_FILE={{ toolchain | replace("/","\\") }}
{% else %}
CONAN_CMAKE_TOOLCHAIN_FILE={{ toolchain }}
{% endif %}
CONAN_CMAKE_GENERATOR="Unix Makefiles"
[conf]
tools.android:ndk_path=$android_ndk

